import numpy as np
import pandas as pd

N = 5
data = {
    'A': pd.date_range(start='2016-01-01', periods=N, freq='D'),
    'x': np.linspace(0, stop=N - 1, num=N),
    'y': np.random.rand(N),
    'C': np.random.choice(['Low', 'Medium', 'High'], N).tolist(),
    'D': np.random.normal(100, 10, size=(N)).tolist()
}

label = ['a', 'b', 'c', 'd', 'e']

df = pd.DataFrame(data, index=label)
print(df)

# 遍历字段名
for col in df:
    print(col)

# 以键值对 (key,value) 的形式遍历；
for key, value in df.iteritems():
    print(key, value)

# 以 (row_index,row) 的形式遍历行
for row_index, row in df.iterrows():
    row['a'] = 15
    print(row_index, row)


for row in df.itertuples():
    print(row)
